package com.hzz.web.boss.logs;

import com.hzz.api.log.ILogLoginService;
import com.hzz.dto.log.LogLoginDto;
import com.hzz.dto.user.UserDto;
import com.hzz.framework.PageUtil;
import com.hzz.framework.Response;
import com.hzz.framework.annotation.auth.RequiresPermissions;
import com.hzz.framework.util.CommonConstant;
import com.hzz.framework.util.JwtUtil;
import com.hzz.framework.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("员工登录日志")
@RestController
@Slf4j
public class LogLoginController extends BaseController {
    private static final String acPrefix = "/boss/logs/logLogin/";
    @Autowired
    ILogLoginService logLoginService;

    @RequiresPermissions("logLogin:menu")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "page/{pageNum}")
    // @ApiOperation(value = "信息分页(未删除)")
    public Response page(@ModelAttribute LogLoginDto dto, @PathVariable("pageNum") Integer pageNum) {
        log.info("LogLoginController page.........");
        Response result = new Response();
        try {
                dto.setPageSize(CommonConstant.PAGEROW_DEFAULT_COUNT);
            dto.setPageNum(pageNum);
            UserDto staffDto = JwtUtil.getSubject(UserDto.class);
            dto.setStaffId(staffDto.getId());
            dto.setIsSuper(staffDto.getIsSuper());

            result.data = PageUtil.copy(logLoginService.findDataIsPage(dto));
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }


    @RequiresPermissions("logLogin:info")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "info/{id}")
    // @ApiOperation(value = "信息详情")
    public Response info(@PathVariable("id") Long id) {
        log.info("LogLoginController info.........");
        Response result = new Response();
        try {
            LogLoginDto dto = new LogLoginDto() {{
                setId(id);

                UserDto staffDto = JwtUtil.getSubject(UserDto.class);
                setStaffId(staffDto.getId());
                setIsSuper(staffDto.getIsSuper());
            }};
            result.data = logLoginService.findDataById(dto);
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }

//    @RequiresPermissions("logLogin:phydel")
//    @RequestMapping(method = RequestMethod.POST, value = acPrefix + "phydel/{id}")
//    @ALogOperation(type = "删除", desc = "员工登录日志-物理删除")
//    // @ApiOperation(value = "物理删除")
//    public Response phydel(@PathVariable("id") Long id) {
//        log.info("LogLoginController phydel.........");
//        Response result = new Response(0, "success");
//        try {
//            LogLoginDto dto = new LogLoginDto() {{
//                setId(id);
//                UserDto staffDto = JwtUtil.getSubject(UserDto.class);
//                setStaffId(staffDto.getId());
//                setIsSuper(staffDto.getIsSuper());
//
//            }};
//            result.message = logLoginService.deleteData(dto);
//        } catch (Exception e) {
//            result = Response.error(e.getMessage());
//        }
//        return result;
//    }
}